/**
 * @project 黄鹤楼酒业质量管理系统(QMS)
 * @module 模块:
 * @desc: 描述:
 * @author: 王丹
 * @create: 2023-11-30 09:20
 **/
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.io.UnsupportedEncodingException;
import java.net.URL;
import java.net.URLConnection;
import java.net.URLEncoder;

public class PostDemo {
    private static final String EPID = "73028";
    private static final String USER_NAME = "hhljy";
    private static final String PASSWORD = "3689f0f6bf74d450";
    private static final String URL = "http://61.191.26.189:8888/smser.ashx";

    public static void main(String[] args) throws UnsupportedEncodingException {
        String phone = "18298192990";
        String content = "【xxx】您的短信验证码是109765,三分钟内有效";
        String param = "f=1&uid=" + EPID + "&un=" + USER_NAME + "&pw=" + PASSWORD + "&p=" + phone
                + "&i=" + URLEncoder.encode(content, "UTF-8");
        String result = sendPost(URL, param);
        System.out.println("result = " + result);
    }

    public static String sendPost(String url, String param) {
        PrintWriter out = null;
        BufferedReader in = null;
        String result = "";
        try {
            URL realUrl = new URL(url);
            URLConnection conn = realUrl.openConnection();
            conn.setConnectTimeout(1000 * 60);
            conn.setReadTimeout(1000 * 60);
            conn.setRequestProperty("accept", "*/*");
            conn.setRequestProperty("connection", "Keep-Alive");
            conn.setRequestProperty("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;SV1)");
            conn.setRequestProperty("Accept-Charset", "UTF-8");
            conn.setRequestProperty("content-type", "application/x-www-form-urlencoded;charset=UTF-8");
            conn.setDoOutput(true);
            conn.setDoInput(true);
            out = new PrintWriter(conn.getOutputStream());
            out.print(param);
            out.flush();
            in = new BufferedReader(new InputStreamReader(conn.getInputStream(), "utf-8"));
            String line;
            while ((line = in.readLine()) != null) {
                result += line;
            }
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            try {
                if (out != null) {
                    out.close();
                }
                if (in != null) {
                    in.close();
                }
            } catch (IOException ex) {
                ex.printStackTrace();
            }
        }
        return result;
    }
}

